package com.fastadmin.controller;

import cn.hutool.core.util.StrUtil;
import com.fastadmin.common.mapper.BeanMapper;
import com.fastadmin.mapper.impl.UserMapper;
import com.fastadmin.pojo.User;
import com.fastadmin.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequiredArgsConstructor
public class ProfileController extends BaseController {
    private final UserMapper userMapper;
    private final UserService userService;

    @RequestMapping("api/profile/index")
    public String profile(Model model) {
        User user = getUser();
        model.addAttribute("user", user);
        return "sys/profile/index";
    }


    @RequestMapping("api/profile/edit")
    @ResponseBody
    public Object edit(Model model,User user) {
        user.setId(getUser().getId());
        userMapper.updateByPrimaryKeySelective(user);
        super.updateUserCache();
        return ok();
    }
}
